import time

from _spice_path import spice_path

def _Command(spiceref,pid,scriptpath,commandtext):
    writevi=spiceref.GetVIReference(spice_path + '\\common\\Utilities\\system_utilities\\BufferFileOperations.vi')
    parname1='Path'
    parname2='Operation'
    parname3='Input String Array'
    parname4='Input String'
    parname5='Output String'
    parname6='Boolean Output'
    parname7='Integer output'
    parnames=parname1,parname2,parname3,parname4,parname5,parname6,parname7
    parvalues=scriptpath,3,(),commandtext,'',0,0
    writevi.Call(parnames,parvalues)
    #Now we go into a while loop to wait to see if the command is finished
    finished=0
    checkvi=spiceref.GetVIReference(spice_path + '\\common\\scripting\\ScriptCommandFinished.vi')
    while finished==0:
        parnames='PID Input','Is Command Finished?'
        parvalues=pid,0
        returnnames,returnvals=checkvi.Call(parnames,parvalues)
        finished=returnvals[1]
        time.sleep(0.25)
    return
